package com.aabte.servlet;

import com.aabte.service.HelloService;

import javax.servlet.*;
import javax.servlet.annotation.HandlesTypes;
import java.util.EnumSet;
import java.util.Set;

@HandlesTypes(value = {HelloService.class})
public class MyServletContainerInitializer implements ServletContainerInitializer {
    @Override
    public void onStartup(Set<Class<?>> set, ServletContext servletContext) throws ServletException {

        System.err.println("感兴趣的类：");
        if (null != set) {
            for (Class<?> clz : set) {
                System.err.println(clz.getName());
            }
        }

        // 注册Servlet
        ServletRegistration.Dynamic userServlet = servletContext.addServlet("userServlet", new UserServlet());
        // 配置映射路径
        userServlet.addMapping("/user");

        // 注册Filter
        FilterRegistration.Dynamic userFilter = servletContext.addFilter("userFilter", new UserFilter());
        // 配置过滤url规则
        userFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");

        // 注册Listener
        servletContext.addListener(UserListener.class);
    }
}
